package com.berry.MedCheck.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.berry.MedCheck.R;

/**
 * Created with IntelliJ IDEA.
 * User: Airay.Rong
 * Date: 13-5-13
 * Time: 上午9:37
 * To change this template use File | Settings | File Templates.
 */
public class LabelText extends LinearLayout {
	private TextView mLabel;
	private TextView mText;
	private TextView mComm;
	public LabelText(Context context) {
		super(context);
	}

	public LabelText(Context context, AttributeSet attrs) {
		super(context, attrs);
		setOrientation(HORIZONTAL);
		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.labeltext);
		CharSequence labelText = ta.getText(R.styleable.labeltext_label);
		CharSequence textText = ta.getText(R.styleable.labeltext_text);
		int labelColor = ta.getColor(R.styleable.labeltext_labelColor, Color.RED);
		int textColor = ta.getColor(R.styleable.labeltext_textColor,Color.BLACK);
		int labelSize = ta.getInteger(R.styleable.labeltext_labelSize,30);
		int textSzie = ta.getInteger(R.styleable.labeltext_textSize,30);
		ta.recycle();

		LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		li.inflate(R.layout.labletext,this,true);
		mLabel = (TextView) findViewById(R.id.label);
		mText = (TextView) findViewById(R.id.text);
		mComm = (TextView) findViewById(R.id.commar);
		if (labelColor != 0) {
			setLabelColor(labelColor);
		}
		if (textColor != 0){
			setTextColor(textColor);
		}
		if (labelText != null) {
			setLabel(labelText);
		}
		if (textText != null) {
			mText.setText(textText);
		}
		if (labelSize !=0){
			mLabel.setTextSize(labelSize);
			mComm.setTextSize(labelSize);
		}
		if (textSzie != 0){
			mText.setTextSize(textSzie);
		}
	}
	public void setLabel(CharSequence t){
		mLabel.setText(t);
	}
	public void setLabel (int resid){
		setLabel(getContext().getResources().getText(resid));
	}
	public void setText(CharSequence t){
		mText.setText(t);
	}
	public void setText(int id){
		setText(getContext().getResources().getText(id));
	}
	public void setLabelColor(int color){
		mLabel.setTextColor(color);
		mComm.setTextColor(color);
	}
	public void setTextColor(int color){
		mText.setTextColor(color);
	}

	public CharSequence getText() {
		return mText.getText();
	}



}

